package com.test.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.GatheringByteChannel;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class Marketing {
	public static void main(String[] args) throws Exception {
		int reps = 10;
		FileOutputStream fos = new FileOutputStream(DEMOGRAPHIC);
		GatheringByteChannel gatherChannel = fos.getChannel();
		ByteBuffer[] bs = utterBS(reps);
		while(gatherChannel.write(bs) > 0){
			
		}
		System.out.println("Mindshare paradigms synergized to " + DEMOGRAPHIC);
	}

	public static ByteBuffer[] utterBS(int howMany) throws Exception {
		List list = new LinkedList();
		for (int i = 0; i < howMany; i++) {
			list.add(pickRandom(col1, " "));
			list.add(pickRandom(col2, " "));
			list.add(pickRandom(col3, newline));
		}
		ByteBuffer[] bufs = new ByteBuffer[list.size()];
		list.toArray(bufs);
		return bufs;
	}

	public static ByteBuffer pickRandom(String[] strings, String suffix)
			throws Exception {
		String string = strings[rand.nextInt(strings.length)];
		int total = string.length() + suffix.length();
		ByteBuffer buf = ByteBuffer.allocate(total);
		buf.put(string.getBytes("US-ASCII"));
		buf.put(suffix.getBytes("US-ASCII"));
		buf.flip();
		return buf;
	}

	public static final String DEMOGRAPHIC = "E:/test3.txt";
	public static Random rand = new Random();
	public static String[] col1 = { "Aggregete", "Enable", "Leverage",
			"Facilitate", "Synergize", "Reperpose", "Strategize", "Reinvent",
			"Harness" };
	public static String[] col2 = { "cross-platform", "best-of-breed",
			"frictionless", "ubiquitous", "extensible", "compelling",
			"mission-critical", "collaborative", "integrated" };
	public static String[] col3 = { "methodologies", "infomediaries",
			"platforms", "schemas", "mindshare", "paradigms",
			"functionalities", "wev services", "infrastructures" };
	public static String newline = System.getProperty("line.separator");
}
